package com.bigshen.demo.annotation.configurecomponents.a5Imports;

import com.bigshen.demo.project.entity.World;
import org.junit.Test;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.util.Arrays;

public class MyTest {

    @Test
    public void test() {

        ApplicationContext applicationContext = new AnnotationConfigApplicationContext(MyConfig.class);

        String[] beanNames = applicationContext.getBeanDefinitionNames();
        System.out.println(
                Arrays.toString(beanNames).replaceAll("\\[", "").replaceAll(",", "\n").replaceAll("\\]", " ")
        );

        System.out.println("------------------ ");

        // world在MyConfig内是创建的MyFactoryBean，但是从IOC容器中取出的是World对象
        World world = (World) applicationContext.getBean("world");
        System.out.println(world);

        World world2 = (World) applicationContext.getBean("world");
        System.out.println(world2);

        System.out.println(world == world2);

        // 怎么从IOC容器中取出FactoryBean
        FactoryBean<World> factoryBean = (FactoryBean<World>) applicationContext.getBean("&world");
        System.out.println(factoryBean);

    }

}
